package org.scboy.common.dynamic.node.logicNode;

import org.scboy.common.annotation.ScriptNode;
import org.scboy.common.dynamic.node.BaseNode;

import cn.hutool.json.JSONObject;

@ScriptNode(value="LOGIC_FOREACH_CONTINUE")
public class LogicContinueNode extends BaseNode {

	@Override
	public void create(JSONObject object) {
		
	}

	@Override
	public Object run() {
		/**
		 * 测试日志
		 */
		if(this.script.isTest()) {
			this.script.appendMsg("----->开始执行："+getNodeName()+" 节点ID："+this.getId());
		}
		
		BaseNode branchNode=getBranchNode();
		
		if(branchNode==null) {
			throw new RuntimeException(getNodeName()+"属于循环内节点，当前节点不在循环节点的循环流内。");
		}
		
		//设置循环索引
		branchNode.setData("_index", ((int)branchNode.getData("_index"))+1);
		/**
		 * 测试日志
		 */
		if(this.script.isTest()) {
			this.script.appendMsg("缓存数据：\r\n"+entityToString(this.getDataAll()));
			this.script.appendMsg("执行下个节点："+branchNode.getNodeName()+" 节点ID："+branchNode.getId());
		}
		return branchNode.run();
	}

}
